// ConnectToMap.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h"
#include "ConnectToMap.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CConnectToMap dialog


CConnectToMap::CConnectToMap(CWnd* pParent /*=NULL*/)
	: CDialog(CConnectToMap::IDD, pParent)
{
	//{{AFX_DATA_INIT(CConnectToMap)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CConnectToMap::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CConnectToMap)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CConnectToMap, CDialog)
	//{{AFX_MSG_MAP(CConnectToMap)
	ON_BN_CLICKED(IDC_Play, OnPlay)
	ON_BN_CLICKED(IDC_Stop, OnStop)
	ON_BN_CLICKED(IDC_Pause, OnPause)
	ON_WM_CLOSE()
	ON_MESSAGE (WM_CONNECT_COMPLETE, OnConnectExit)
	ON_MESSAGE (WM_CONNECT_PROGRESS, OnConnectProgress)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CConnectToMap message handlers

BOOL CConnectToMap::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	if (!m_ConnectToMap.Create(this))
	{
		g_GlobalObj.UIWriteLog("m_ConnectToMap.Create Error");
		OnClose();
	}
	

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CConnectToMap::OnPlay() 
{
	if(!m_ConnectToMap.StartConnect())
		g_GlobalObj.UIWriteLog("m_ConnectToMap.StartConnect Error");
	
}

void CConnectToMap::OnStop() 
{
	if(!m_ConnectToMap.StopConnect())
		g_GlobalObj.UIWriteLog("m_ConnectToMap.StopConnect Error");
	
}

void CConnectToMap::OnPause() 
{
	if(!m_ConnectToMap.PauseConnect())
		g_GlobalObj.UIWriteLog("m_ConnectToMap.PauseConnect Error");
	
}
void CConnectToMap::OnClose() 
{
	OnOK();
///	if(!m_ConnectToMap.CloseWindow())
///		g_GlobalObj.UIWriteLog("m_ConnectToMap.CloseWindow Error");
///	CDialog::OnClose();
}

LONG CConnectToMap :: OnConnectExit(UINT wParam, LONG lParam)
{
	if(!m_ConnectToMap.ConnectThreadExit())
		g_GlobalObj.UIWriteLog("m_ConnectToMap.ConnectThreadExit Error");
	
	return true;
}

LONG CConnectToMap::OnConnectProgress (UINT wParam, LONG lParam)
{
	if (!m_ConnectToMap.ConnectProgress((int) lParam))
		g_GlobalObj.UIWriteLog("m_ConvertToNMEA.ConnectProgress Error");

	return true;
}

void CConnectToMap::OnOK() 
{
	if(!m_ConnectToMap.ShutDown())
		g_GlobalObj.UIWriteLog("m_ConnectToMap.ShutDown Error");

	CDialog::OnOK();
}
